/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isSymmetric = function(root) {
    if(!root)return true;
    return isSymmetricTree(root.left, root.right);
};

function isSymmetricTree(node1, node2) {
    if(!node1&&!node2)return true;
    if(node1&&node2){
        if(node1.val!==node2.val)return false;

        let val1 = isSymmetricTree(node1.left,node2.right);
        let val2 = isSymmetricTree(node1.right,node2.left);

        return val1 && val2;
    }
    return false;
}